#ifndef __LOG_H__
#define __LOG_H__

#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <sys/stat.h>

#ifdef _DEBUG_
#define DEBUG(format,...) \
        printf("FILE:"__FILE__",LINE:%05d:"format,__LINE__,##__VA_ARGS__)
#else 
#define DEBUG(format,...)
#endif

#define LOG_FILE   "./lib/log.txt"

#define LOG(format, ...) \
    do { \
        time_t t = time(0); \
        struct tm ttt = *localtime(&t); \
        if (access("./lib", F_OK) != 0) \
            mkdir("./lib", 0777); \
        FILE *fp_log = NULL; \
        fp_log = fopen(LOG_FILE, "ab+"); \
        fprintf(fp_log, "[INFO]%4d-%02d-%02d %02d:%02d:%02d--"format"\n", \
        ttt.tm_year + 1900, ttt.tm_mon + 1, ttt.tm_mday, ttt.tm_hour, ttt.tm_min, ttt.tm_sec, ##__VA_ARGS__); \
        fclose(fp_log); \
    } while (0)

#endif